package ycl.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import ycl.system.req.SysUserReq;
import ycl.common.result.Result;
import ycl.common.base.controller.BaseController;
import ycl.common.result.REnum;
import ycl.common.exception.CustomException;
import ycl.common.models.base.A;
import ycl.common.models.req.base.ObjReq;
import ycl.system.entity.SysUser;
import ycl.system.req.UserPrefectReq;
import ycl.system.res.SysUserRes;
import ycl.system.service.SysUserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author ycl
 * @since 2022-03-03 11:43:57
 */
@RestController
@RequestMapping("/sys-user")
@Api(tags = "用户")
public class SysUserController extends BaseController<SysUser, SysUserReq, SysUserRes> {
	@Resource
	private SysUserService sysUserService;

	@Override
	public Result<Page<SysUserRes>> pageList(HttpServletRequest request, SysUser sysUser) {
		return Result.success(sysUserService.pageList(request, sysUser, SysUserRes.class));
	}

	@Override
	public <E extends SysUserReq> Result<A> save(HttpServletRequest request, @RequestBody @Valid E e) {
		sysUserService.save(request, e, SysUser.class);
		return Result.success();
	}

	@Override
	public Result<SysUser> deleteBatchIds(HttpServletRequest request, @RequestBody ObjReq<List<Long>> req) {
		throw new CustomException(REnum.CUSTOM_SERVER_REJECT);
	}

	@Override
	public <E extends SysUserReq> Result<A> update(HttpServletRequest request, @RequestBody @Valid E e) {
		sysUserService.update(request, e, SysUser.class);
		return Result.success();
	}


	@PostMapping("prefectDetail")
	@ApiOperation("完善用户信息")
	@ApiOperationSupport(order = 11)
	public Result<A> prefectDetail(HttpServletRequest request, @RequestBody @Valid UserPrefectReq req) {
		sysUserService.prefectDetail(request, req);
		return Result.success();
	}
}

